package org.springblade.modules.notice.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springblade.modules.notice.vo.CommonEnumInfo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author ysq
 * @Date 2024/11/21
 * @Description 推送对象枚举
 */
@Getter
@AllArgsConstructor
public enum PushObjectEnum {

	P_TASK_EXECUTOR(1, "任务执行人", new Integer[] { BusinessType.REPAIR.getCode(), BusinessType.RESCUE.getCode(), BusinessType.ABARBEITUNG.getCode() }),

	P_TASK_CREATOR(2, "任务创建人", new Integer[] { BusinessType.REPAIR.getCode(), BusinessType.RESCUE.getCode(), BusinessType.ABARBEITUNG.getCode() }),

	P_ELE_TEAM_LEADER(3, "工单电梯负责组-维保组长",  new Integer[] { BusinessType.REPAIR.getCode(), BusinessType.RESCUE.getCode(), BusinessType.ABARBEITUNG.getCode() }),

	P_TASK_APPROVER(4, "工单审批人",  new Integer[] { BusinessType.REPAIR.getCode(), BusinessType.RESCUE.getCode(), BusinessType.ABARBEITUNG.getCode() }),

	P_TASK_ELE_MANAGER(5, "工单电梯管理人",  new Integer[] { BusinessType.RESCUE.getCode() }),

	P_RESCUE_TASK_BUILDING_MANAGER(6, "工单项目管理人",  new Integer[] { BusinessType.RESCUE.getCode() }),  // 只针对救援工单可用

	P_ELE_TEAM_SUPERVISOR(7, "工单电梯负责组-维保主管",  new Integer[] { BusinessType.RESCUE.getCode() }),

	P_ROLE_WAITER(8, "客服",  new Integer[] { BusinessType.RESCUE.getCode() }),

	;

	private final Integer code;

	private final String desc;

	/**
	 * 作用范围，对应code集合
	 * @see BusinessType
	 */
	private final Integer[] scopes;

	/**
	 * 获取可选列表
	 * @param businessType 业务类型
	 */
	public static List<CommonEnumInfo> getSelectList(Integer businessType) {
		List<CommonEnumInfo> list = new ArrayList<>(16);
		for (PushObjectEnum value : values()) {
			if (businessType != null) {
				if (!Arrays.asList(value.getScopes()).contains(businessType)) {
					continue;
				}
			}
			list.add(new CommonEnumInfo(value.getCode(), value.getDesc()));
		}
		return list;
	}

	/**
	 * 根据code获取描述
	 * @param code
	 * @return
	 */
	public static String getDesc(Integer code) {
		for (PushObjectEnum value : values()) {
			if (value.getCode().equals(code)) {
				return value.getDesc();
			}
		}
		return null;
	}
}
